// 对数据库进行初始化文件
const sequelize  = require("./dbConnect") //实例
const adminModel = require("./model/adminModel")    //数据模型
const bannerModel = require("./model/bannerModel")
const md5 = require("md5")

async function init(){

    // 数据模型和表同步
    await sequelize.sync({
        alter:true
    })

    // 初始化用户
    const adminCount = await adminModel.count()
    if(!adminCount){
        await adminModel.create({
            loginId : "admin",
            name:"超级管理",
            loginPwd: md5("123456")
        })
        console.log("初始化管理员数据完毕");
    }

    // 初始化操作
    const bannerCount = await bannerModel.count()
    if(!bannerCount){
        await bannerModel.bulkCreate([
            {
                midImg:"midg1",
                bigImg:"big1",
                title:"title1",
                desc:"des1"
            },{
                midImg:"midg2",
                bigImg:"big2",
                title:"title2",
                desc:"des2"
            },{
                midImg:"midg3",
                bigImg:"big3",
                title:"title3",
                desc:"des3"
            }
        ])
        console.log("banner初始化完毕");
    }

    console.log("数据库初始化准备完毕");
}

init()